home *** CD-ROM | disk | FTP | other *** search
- *** Adding Z Buffer output to Rayshade 4.0.6, Version 2 ***
-
- Mark Maimone, mwm@cs.cmu.edu
-
- 22 February 1994
- (orig 18 March 1992)
-
- ==============================================================================
- THIS PATCH SUPERCEDES THE ONE POSTED ON 18 MARCH 1992
-
- Version 2 of the Z-buffer patch has several improvements over the
- original. These include:
-
- -- Output distance is the REAL Z coordinate now; the first release
- output the distance from the eye to the object.
- -- Several output formats are available; Heightfield, Text, and
- Expanded text.
- -- The patch is for version 4.0.6, not version 4.0.
-
- It's easy to use; just use the command line argument "-z", e.g.:
-
- rayshade -z depth.hf ....
-
- The default output format is HEIGHTFIELD, but you can specify a text format
- by using a special suffix on the filename:
-
- Example Filename Output Format
- ---------------- -------------
- foo.hf Heightfield
- foo.txt ASCII Text, lines correspond to rows
- foo.etxt Expanded Text, one pixel per line
- with integer coordinates, e.g.,
- 1 5 3.45643
-
- anything else Heightfield
-
- If anyone would care to provide me with a single ASCII "patch" file
- I'd be happy to provide it in place of the current TAR format. I don't know
- the syntax required to get patch to create new files.
-
-
-
- The rest of this file is a copy of the original README file, with just a few
- corrections.
-
- ==============================================================================
- **NOTE** This is *not* an "official" release
- ==============================================================================
-
- I've made a preliminary attempt at getting Rayshade to output depth
- information in addition to rendered images. I need this information since I
- want to use Rayshade to generate test images for a stereo algorithm. Having
- the "true" depth means I can test how accurately my stereo algorithm
- reconstructs it (depth) from only the stereo pair of 2D images without
- knowing the inherent 3D structure.
-
- My technique is quite basic. I rely on the anti-aliasing scheme to
- sample the pixels, and remember the distance from the Eye to the nearest
- object along each generated ray. Of all these distances associated with a
- pixel, I arbitrarily choose the one nearest to the eye to denote the "true"
- distance.
-
- This scheme has several problems (and I'm sure others will find
- more). It doesn't return the distance of the object that occupies *most* of
- the pixel, it merely returns the distance of the object it finds nearest to
- the eye; it doesn't matter if it only occupies 5% of the pixel. It lets the
- antialiasing scheme choose which rays are relevant; a bad antialiasing
- scheme may well yield a bad Z buffer. It treats transparent objects as
- opaque (changing this *should* only require adding a very simple test in
- SampleScreen(), but I don't know enough about the internals yet). It assumes
- all distances are positive (this, at least, should be a reasonable
- assumption).
-
- The changes were realized entirely within the "libshade" directory.
- Adding the Z buffer to rayshade involves several small changes to files in
- that directory, plus the addition of two more (short) source files, zbuf.c
- and zbuf.h.
-
- ======== COMMAND LINE INTERFACE
-
- Very easy. Just run rayshade with the "-z filename" option to write
- the Z buffer to the named file. You must name some file, it won't write to
- stdout.
-
- ======== IMPLEMENTATION
-
- Rayshade already computes everything needed to generate the Z
- buffer, but it throws the information away. I've added an external Float
- array (zbuffer in zbuf.c) to store the distance to the nearest object in
- each pixel. You must have enough memory available for a Float array with
- the same dimensions as the window being rendered.
-
- I put a hook into the routine where Rayshade finds the "first"
- object hit by a given ray (SampleScreen() in libshade/viewing.c). That hook
- calls ZbufAdd() to store the current distance in global array zbuffer.
- ZbufAdd() maps the Float index values to ints by using floor(pix+0.5) for
- both X and Y.
-
- ======== FILE FORMAT
-
- Version 2 of this patch supports three output file formats.
-
- One is the HEIGHTFIELD format. Please see the Rayshade guide for a
- description of this format.
-
- Another is a TEXT format. After some opening comments, each line
- corresponds to a single row in the image. Distances are represented as text
- (e.g. "5.45454") and separated by spaces.
-
- The third is an EXPANDED TEXT format. The first few lines in the
- file are comments describing the source of the data. After that, the depth
- information follows, with each line representing a single pixel:
-
- <int x-coord> <int y-coord> <Float distance>
-
- A distance of -1000 means the pixel denotes background. The file is ordered
- by scanline, with a blank line separating scanlines. This format is ideally
- suited for viewing the depth map using GNUplot (see comments in zbuf.c).
-
- Here's a sample output file:
-
- # Depth Map for Rayshade output file
- # Input RAY file: "../Examples/planet.ray"
- # Resolution for this rendering is 50x50
- # window from (0,0) to (49,49)
- # Index 0: 11412 hits
- 0 0 -1
- 0 1 -1
- 0 2 -1
- 0 3 -1
- . [ I deleted many lines for brevity ]
- .
- 12 13 -1
- 12 14 -1
- 12 15 -1
- 12 16 3.75485
- 12 17 3.60294
- 12 18 3.52262
- 12 19 3.46714
- 12 20 3.42647
- 12 21 3.40308
-
- ======== COMMENTS
-
- Please post any comments to the rayshade-users@cs.princeton.edu
- mailing list, or if you prefer you may send them directly to me at
- mwm@cs.cmu.edu. Any comments are welcome...
-
- Mark Maimone
- CMU Computer Science
- mwm@cs.cmu.edu
-